//
//  HealthWalkViewController.m
//  happyHealthyWalk
//
//  Created by newhuidong on 16/2/23.
//  Copyright © 2016年 HuiDong. All rights reserved.
//

#import "HealthWalkViewController.h"
#import "Header.h"
#import "StepViewController.h"
#import <UIKit/UIKit.h>
#import <HealthKit/HealthKit.h>
@interface HealthWalkViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>{
    
    UIButton * _button;
    UILabel * _label;
    
}
@property (nonatomic, strong) UIViewController *mainVC;


@property(weak,nonatomic)IBOutlet UIImageView * imageView;
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)UILabel * step_label;
@property(nonatomic,strong)UILabel * word_label;

@property(nonatomic,strong)NSArray * dataArr;
@property(nonatomic,strong)NSArray * imageArr;
@property(nonatomic,strong)NSArray * descriptionArr;


@end

@implementation HealthWalkViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH) style:UITableViewStylePlain];
    
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.imageView.frame=CGRectMake(0, 0, ScreenW, 244);
    self.tableView.tableHeaderView=self.imageView;
    [self.view addSubview:self.tableView];
    
    self.edgesForExtendedLayout=UIRectEdgeNone;
    
    self.step_label=[[UILabel alloc]initWithFrame:CGRectMake(ScreenW-100-120, 100, 120, 40)];
    self.step_label.text=@"100000";
    
    self.word_label=[[UILabel alloc]initWithFrame:CGRectMake(ScreenW-100-70, 140, 30, 40)];

    self.word_label.text=@"步";
    self.word_label.textColor=[UIColor whiteColor];
    self.word_label.font=[UIFont systemFontOfSize:20];
    [self.imageView addSubview:self.word_label];
    
    
    self.step_label.textColor=[UIColor whiteColor];
    self.step_label.textAlignment=NSTextAlignmentCenter;
    self.step_label.font=[UIFont systemFontOfSize:20];
    [self.imageView addSubview:self.step_label];
    
    _dataArr=@[@"步数统计",@"累计里程",@"健康总里程"];
    _imageArr=@[@"setp",@"legend",@"allegend"];
    _descriptionArr=@[@"",@"当前排名20",@"当前排名202"];
    
    self.title=@"健康计步";
    
}

-(void)updateUsersFootLabel{
    
    
    
    
    
    
    
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat offSetY= self.tableView.contentOffset.y;
    
    if (offSetY<-52) {
        
        _label.textColor=[UIColor blackColor];
        
        
    }else{
        _label.textColor=[UIColor whiteColor];
        
        
    }
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArr.count;
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * identifer=@"cell";
    
    UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:identifer];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifer];
        
    }
    
    
    cell.textLabel.text=_dataArr[indexPath.row];
    cell.imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",_imageArr[indexPath.row]]];
    cell.detailTextLabel.text=_descriptionArr[indexPath.row];
    cell.detailTextLabel.textColor=[UIColor colorWithRed:32/255.0f green:173/255.0f blue:148/255.0f alpha:1];
    
    
    
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
    
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        
        UIStoryboard * story=[UIStoryboard storyboardWithName:@"HealthWalk" bundle:nil];
        
        
        
    StepViewController * step=[story instantiateViewControllerWithIdentifier:@"StepViewController"];
        
        
    [self.navigationController pushViewController:step animated:YES];
        
        
        
    }else if (indexPath.row==1){
        
    }else if (indexPath.row==2){
        
        
    }else  {
        
        NSLog(@"健康总路程");
        
    }
    
}
-(void)viewWillAppear:(BOOL)animated{
    
    
    [self.navigationController setNavigationBarHidden:YES];
    
  //  self.navigationController.navigationBarHidden=YES;
    
    _button =[UIButton buttonWithType:UIButtonTypeCustom];
    [_button setImage:[UIImage imageNamed:@"backTip"] forState:0];
    _button.frame=CGRectMake(10, 25, 30, 40);
    [self.view addSubview:_button];
    [_button addTarget:self action:@selector(fanhui) forControlEvents:UIControlEventTouchUpInside];
    
    _label=[[UILabel alloc]initWithFrame:CGRectMake((ScreenW-80)/2, 30, 80, 30)];
    _label.text=@"健康计步";
    _label.textAlignment=NSTextAlignmentCenter;
    
    _label.textColor=[UIColor whiteColor];
    _label.font=[UIFont systemFontOfSize:18];
    [self.view addSubview:_label];
    
    
    
}
-(void)viewWillDisappear:(BOOL)animated{
    
    [self.navigationController setNavigationBarHidden:NO];
    
}


-(void)fanhui{
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}
-(void)dealloc{
    _button=nil;
    _label=nil;
    _step_label=nil;
    _tableView=nil;
    
    
    
}
@end
